package com.bigflexlib.mouse
{
	
	
	import com.bigflexlib.core.dependency.DependencySpec;
	import com.bigflexlib.x.mx.core.Application.App;
	
	import flash.display.DisplayObject;
	import flash.events.Event;


	
	public class MousePanner extends MouseTrackerBase
	{


		private var navTracker:MouseNavigationTracker;

			
				
		///////////////////////////////////////////
		// canvas
		///////////////////////////////////////////

		private var canvasSpec:DependencySpec = new DependencySpec( "canvas", "canvasChanged" );
		
		[Bindable("canvasChanged")]
		public function get canvas( ):DisplayObject
		{
			return dh.getDependencyValue( canvasSpec );
		}
		
		public function set canvas( v:DisplayObject ):void
		{
			dh.setDependencyValue( canvasSpec, v );
		}		
		
		
		
		
		public function MousePanner( )
		{
			
			navTracker = new MouseNavigationTracker( );
		
			App.app.addEventListener( Event.ENTER_FRAME, onEnterFrame );
		
		}
		
		
		
		private function onEnterFrame( event:Event ):void
		{
			
			if ( ! enabled )
				return;
			
			try 
			{
				// trace( navTracker.navX + " , " + navTracker.navY );
				target.x += calc( navTracker.navX );
				target.y += calc( navTracker.navY );
			}
			catch ( e:Error ){}
		
		}
		
		private function calc( num:Number ):Number
		{
			var sign:int = num < 0 ? 1 : -1;
			return Math.pow( num * 5, 2 ) * sign;		
		}		
		
		
		
		override protected function dependenciesUpdated( ):void
		{
		
			super.dependenciesUpdated( );
		
		
			if ( dh.modifications[ canvasSpec ] )
			{
				navTracker.target = canvas;			
			}
		
		
		}
		
		
		
		
		
		
	}
	
}

